package com.api

import scala.util.matching.Regex.Match

/**
 * 模式匹配
 */
object Match {
  def main(args: Array[String]): Unit = {
    val tuple5=Tuple6(1,"HELLO",2,false,'K',23.45)
    //遍历元组
    tuple5.productIterator.foreach(println)
    tuple5.productIterator.foreach(p=>{matchTest(p)})
  }

  /**
   * 类似于java中的switch case
   * @param param
   * @return
   */
  def matchTest(param :Any): Any = {
    param match {

      case 1=>println("value is 1")
      case i:Int=>println("type is Int")
      case i:String=>println("type is String")
      case i:Boolean=>println("type is Boolean")
      case c:Char=>println("type is Char")
      case d:Double=>println("type is Double")
      case _=>{
        println("来到模式匹配，_=>类似于default")
      }
    }
  }
}
